export default (params) => {
  return new Promise((resolve, reject) => {
    const baseUrl = 'http://iwenwiki.com:3002/api';
    wx.showLoading({
      title: '加载中......',
    });

    // 获取本地存储的 token
    const token = wx.getStorageSync('token');
    let header = {};
    if (token) {
      header.token = token;
    }

    wx.request({
      url: baseUrl + params.url,
      method: params.method || 'GET',
      data: params.data || {},
      header,
      success: (res) => {
        resolve(res.data);
      },
      fail: (error) => {
        console.error('Request failed:', error);
        reject(error);
      },
      complete: () => {
        wx.hideLoading();
      },
    });
  });
};
